import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'

export default {
  toast(message: string, type: any = 'success', duration: number = 1000) {
    ElMessage({
      message: message,
      grouping: true,
      type: type,
      duration: duration
    })
  },

  alert(message: string, type: any = 'warning', title: string = '提示') {
    const promise = new Promise((resolve) => {
      ElMessageBox.alert(message, title, {
        type: type,
        draggable: true
      })
        .then(() => {
          resolve(true)
        })
        .catch(() => {
          resolve(false)
        })
    })

    return promise
  },

  confirm(message: string, type: any = 'warning', title: string = '提示') {
    const promise = new Promise((resolve) => {
      ElMessageBox.confirm(message, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: type,
        draggable: true,
        buttonSize: 'default'
      })
        .then(() => {
          resolve(true)
        })
        .catch(() => {
          resolve(false)
        })
    })

    return promise
  },

  prompt(message: string, title: string = '提示') {
    const promise = new Promise((resolve) => {
      ElMessageBox.prompt(message, title, {})
        .then(({ value }) => {
          resolve(value)
        })
        .catch(() => {
          resolve(false)
        })
    })

    return promise
  },

  notice(message: any, title: string, position: any = 'top-right', icon: string = 'RemoveFilled', customClass:any, appendTo:any) {
    ElNotification({
      title: title,
      message: message,
      position: position,
      duration: 2000,
      customClass: customClass,
      appendTo: appendTo,
      icon: icon
    })
  }
}
